﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace AJAX_learning.Chapter9
{
	public partial class Chapter9a : System.Web.UI.Page
	{
		protected override void OnLoad(EventArgs e)
		{
			base.OnLoad(e);

			if (!this.IsPostBack)
			{
				// Создать источник данных.
				var ht = new Hashtable();
				ht.Add("Lasagna", "Key1");
				ht.Add("Spaghetti", "Key2");
				ht.Add("Pizza", "Key3");

				// Установить свойство DataSource элементов управления.
				Select1.DataSource = ht;
				Select2.DataSource = ht;
				Listbox1.DataSource = ht;
				DropdownList1.DataSource = ht;
				CheckList1.DataSource = ht;
				OptionList1.DataSource = ht;
				// Привязать элементы управления.
				this.DataBind();
			}
		}

		protected string TestString
		{
			get { return "Trululu-trulala!"; }
		}

		protected void GetSelectedButtonOnClick(object sender, EventArgs e)
		{
			Result.Text += "- Item selected in Select1: " + Select1.Items[Select1.SelectedIndex].Text + " - " + Select1.Value + "<br />";
			Result.Text += "- Item selected in Select2: " + Select2.Items[Select2.SelectedIndex].Text + " - " + Select2.Value + "<br />";
			Result.Text += "- Item selected in Listbox1: " + Listbox1.SelectedItem.Text + " - " + Listbox1.SelectedItem.Value + "<br />";
			Result.Text += "- Item selected in DropdownList1: " + DropdownList1.SelectedItem.Text + " - " + DropdownList1.SelectedItem.Value + "<br />";
			Result.Text += "- Item selected in OptionList1: " + OptionList1.SelectedItem.Text + " - " + OptionList1.SelectedItem.Value + "<br />";
			Result.Text += "- Items selected in CheckList1: ";
			foreach (ListItem li in CheckList1.Items)
			{
				if (li.Selected)
					Result.Text += li.Text + " - " + li.Value + " ";
			}
		}
	}
}